def add_zhangwu():
    print("添加账务格式为：类别 账户 金额 时间 说明")
    add_list = []
    add_list.append(input("请输入类型"))
    add_list.append(input("请输入账户"))
    add_list.append(input("请输入金额"))
    add_list.append(input("请输入时间"))
    add_list.append(input("请输入说明"))
    lisi_list.append(add_list)
    print("添加账务成功！")
    for i in range(0, len(lisi_list)):
        if i == 0:
            zifu = "ID\t"
        else:
            zifu = f"{i}\t"
        for x in range(0, len(lisi_list[i])):
            zifu = zifu + str(lisi_list[i][x]) + '\t'
        print(zifu)


def change_zhangwu():
    change_ID = int(input("请输入需要编辑的账务ID："))
    change = input('想要修改哪一项：')
    new = input('修改内容为：')
    if change == '类别':
        lisi_list[change_ID][0] = new
    elif change == '账户':
        lisi_list[change_ID][1] = new
    elif change == '金额':
        lisi_list[change_ID][2] = new
    elif change == '时间':
        lisi_list[change_ID][3] = new
    elif change == '说明':
        lisi_list[change_ID][4] = new


def del_zhangwu():
    del_list = int(input("请输入想删除的账务ID："))
    lisi_list.pop(del_list)
    print("删除成功")


def find():
    word = input("请输入关键字（不支持模糊搜索）：")
    new_find_list=[['类别', '账户', '金额', '时间', '说明']]
    for i in lisi_list:
        if word in i:
            new_find_list.append(i)
        else:
            continue
    for i in range(0, len(new_find_list)):
        if i == 0:
            zifu = "ID\t"
        else:
            zifu = f"{i}\t"
        for x in range(0, len(new_find_list[i])):
            zifu = zifu + str(new_find_list[i][x]) + '\t'
        print(zifu)


user_list = [['admin', '123456'], ['lisi', '123456']]

admin_list = ['1.添加账务', '2.编辑账务', '3.删除账务', '4.查询账务', '5.退出系统']
find_list = ['1.查询所有', '2.按条件查询']
lisi_list = [['类别', '账户', '金额', '时间', '说明'],
             ["吃饭支出", "交通银行", 247.8, "2016-03-12", "家庭聚餐"],
             ["工资收入", "现金", 12345.0, "2016-03-15", "开工资了"],
             ["服装支出", "现金", 1200.0, "2016-04-16", "买衣服"],
             ["股票支出", "工商银行", 4500.36, "2017-05-06", "股票大涨，买买买"]
             ]

for i in range(1, 4):
    username = input("请输入用户名")
    password = input("请输入密码")
    if username == 'admin' and password == '123456':
        print("管理员登陆成功")
        break
    elif username == 'lisi' and password == '123456':
        print("普通用户登陆成功")
        break
    else:
        print(f"登录失败，当前为第{i}次，累计3次后禁止登录")

while True:
    # 管理员
    if username == 'admin':
        print(admin_list)
        do = input("请输入要操作的功能序号[1-5]：")
        if do.isdigit():
            do = int(do)
            # 执行添加账务
            if do == 1:
                add_zhangwu()
            # 执行修改账务
            elif do == 2:
                change_zhangwu()
            # 执行删除帐务
            elif do == 3:
                del_zhangwu()
            # 执行查询账务
            elif do == 4:
                for i in range(0, len(lisi_list)):
                    if i == 0:
                        zifu = "ID\t"
                    else:
                        zifu = f"{i}\t"
                    for x in range(0, len(lisi_list[i])):
                        zifu = zifu + str(lisi_list[i][x]) + '\t'
                    print(zifu)
            # 执行退出系统
            elif do == 5:
                print("退出系统")
                exit()

        else:
            print("输入错误，请重新输入：")
    elif username == 'lisi':
        print(find_list)
        lisi_choose = int(input("请输入要操作的功能序号[1-2]："))
        if lisi_choose == 1:
            for i in range(0, len(lisi_list)):
                if i == 0:
                    zifu = "ID\t"
                else:
                    zifu = f"{i}\t"
                for x in range(0, len(lisi_list[i])):
                    zifu = zifu + str(lisi_list[i][x]) + '\t'
                print(zifu)
        elif lisi_choose == 2:
            find()

    # 是否继续程序
    admin_exit = input('是否继续使用？yes/no')
    if admin_exit == 'yes':
        continue
    elif admin_exit == 'no':
        print("程序结束")
        exit()
